package com.itheima.controller;

import com.itheima.service.PetBranchService;
import com.itheima.pojo.Branch;
import com.itheima.pojo.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/admin/Branches")
@RestController
public class PetBranchController {
    private static final Logger log = LoggerFactory.getLogger(PetBranchController.class);
    @Autowired
    private PetBranchService petBranchService;

    //添加门店
    @PostMapping
    public Result addBranch(@RequestBody Branch branch){
        petBranchService.addBranch(branch);
        return Result.success();
    }

    //删除门店
    @DeleteMapping
    public Result deleteBranch(Integer id){
        petBranchService.deleteBranch(id);
        return Result.success();
    }

    //修改门店
    @PutMapping
    public Result updateBranch(@RequestBody Branch branch){
        petBranchService.updateBranch(branch);
        return Result.success();
    }

    //查询门店(根据ID查询门店)
    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id){
        Branch branch = petBranchService.getInfo(id);
        return Result.success(branch);
    }

    //门店列表查询
    @GetMapping
    public Result list(){
        List<Branch> branchList = petBranchService.getBranchList();
        return Result.success(branchList);
    }
}
